package com.yunyi.dm.singleton;

/**
 * 懒汉式
 * 双重检查锁
 *
 * @author yunyi
 */
public class LazyMode03 {

    private static volatile LazyMode03 instance;

    public static LazyMode03 getInstance() {
        //第一次判断，如果instance的值不为null，不需要抢占锁，直接返回对象
        if (instance == null) {
            synchronized (LazyMode03.class) {
                //抢到锁之后在判断是否为null
                if (instance == null) {
                    instance = new LazyMode03();
                }
            }
            instance = new LazyMode03();
        }
        return instance;
    }

    private LazyMode03() {
    }
}
